package main.java.jdk8;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class CollectionTest {
	public static void main(String[] args) {
		ConcurrentHashMap<Integer, Integer> concurrentHashMap = new ConcurrentHashMap<Integer, Integer>();

		long a = System.currentTimeMillis();
		for (int i = 0; i < 1000000; i++) {
			concurrentHashMap.put(i, i);
		}

		long b = System.currentTimeMillis();

		concurrentHashMap.forEach((x, y) -> {
			concurrentHashMap.put(x, x + 1);
		});

		long c = System.currentTimeMillis();

		concurrentHashMap.keySet().parallelStream().forEach(x -> {
			concurrentHashMap.put(x, x + 1);
		});

		long d = System.currentTimeMillis();

		System.out.println("填充数据时间：" + (b - a));
		System.out.println("顺序时间：" + (c - b));
		System.out.println("多线程时间：" + (d - c));
	}
}
